package cn.star.jots.subjectSort.service.impl;

import cn.star.jots.subjectSort.mapper.SubjectSortMapper;
import cn.star.jots.subjectSort.pojo.dto.SubjectSortQuery;
import cn.star.jots.subjectSort.pojo.dto.SubjectSortSaveParam;
import cn.star.jots.subjectSort.pojo.entity.SubjectSort;
import cn.star.jots.subjectSort.pojo.vo.SubjectSortVO;
import cn.star.jots.subjectSort.service.SubjectSortService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class SubjectSortServiceImpl implements SubjectSortService {

    @Autowired
    SubjectSortMapper subjectSortMapper;

    @Override
    public List<SubjectSortVO> selectAll(SubjectSortQuery subjectSortQuery) {
        log.debug("查询专题,参数:{}", subjectSortQuery);
        return subjectSortMapper.selectAll(subjectSortQuery);
    }

    @Override
    public void deleteById(Long id) {
        log.debug("删除专题,参数:{}", id);
        subjectSortMapper.deleteById(id);
    }

    @Override
    public void save(SubjectSortSaveParam subjectSortSaveParam) {
        log.debug("保存专题,参数:{}", subjectSortSaveParam);
        SubjectSort subjectSort = new SubjectSort();
        BeanUtils.copyProperties(subjectSortSaveParam, subjectSort);
        if (subjectSortSaveParam.getId() == null){
            subjectSort.setCreateTime(new Date());
            subjectSortMapper.insert(subjectSort);
        } else {
            subjectSort.setUpdateTime(new Date());
            subjectSortMapper.update(subjectSort);
        }

    }
}
